/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opds.kurs.work.view;

import java.awt.Color;
import opds.kurs.work.core.Constants;
import opds.kurs.work.core.TableMethod;
import opds.kurs.work.core.Util;
import java.util.regex.*;

/**
 *
 * @author hobbit, pol
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public int[][] table;
    public int[] g;
    public int[] f;
    public int[] h;
    public int[] res;

    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        polinomButtonGroup = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        javax.swing.JRadioButton firstPolinomRadioButton = new javax.swing.JRadioButton();
        secondPolinomRadioButton = new javax.swing.JRadioButton();
        thirdPolinomRadioButton = new javax.swing.JRadioButton();
        customPolinomRadioButton = new javax.swing.JRadioButton();
        fourthPolinomRadioButton = new javax.swing.JRadioButton();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        countMatrixG = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jTextField2 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        polinomButtonGroup.add(firstPolinomRadioButton);
        firstPolinomRadioButton.setSelected(true);
        firstPolinomRadioButton.setText("x^10 + x^9 + x^7 +x +1");
        firstPolinomRadioButton.setActionCommand("1");
        firstPolinomRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                firstPolinomRadioButtonActionPerformed(evt);
            }
        });

        polinomButtonGroup.add(secondPolinomRadioButton);
        secondPolinomRadioButton.setText("x^10 + x^9 + x^6 + x^5 + x^4 + x^2+1");
        secondPolinomRadioButton.setActionCommand("2");
        secondPolinomRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                secondPolinomRadioButtonActionPerformed1(evt);
            }
        });

        polinomButtonGroup.add(thirdPolinomRadioButton);
        thirdPolinomRadioButton.setText("x^10 + x^9 + x^8 + x^7 + x^6 + x^4 + x^3 + x^2 + x + 1");
        thirdPolinomRadioButton.setActionCommand("4");
        thirdPolinomRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                thirdPolinomRadioButtonActionPerformed(evt);
            }
        });

        polinomButtonGroup.add(customPolinomRadioButton);
        customPolinomRadioButton.setText("Введите свой полином");
        customPolinomRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customPolinomRadioButtonActionPerformed(evt);
            }
        });
        customPolinomRadioButton.setActionCommand("4");

        polinomButtonGroup.add(fourthPolinomRadioButton);
        fourthPolinomRadioButton.setText("x^10 + x^9 + x^4 + x^3 + 1");
        fourthPolinomRadioButton.setActionCommand("3");
        fourthPolinomRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fourthPolinomRadioButtonActionPerformed(evt);
            }
        });

        jTextField1.setColumns(10);
        jTextField1.setColumns(15);
        jTextField1.setText("000000000000000");
        jTextField1.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                jTextField1InputMethodTextChanged(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane2.setViewportView(jTextArea2);

        jLabel1.setText("G(15, 5)");

        jLabel2.setText("H(15,5)");

        countMatrixG.setText("Посчитать G(15, 5)");
        countMatrixG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                countMatrixGActionPerformed(evt);
            }
        });

        jButton2.setText("Посчитать H(15, 5)");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel3.setText("Выберите полином:");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(25, 25, 25)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 205, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(0, 0, Short.MAX_VALUE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(fourthPolinomRadioButton)
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(customPolinomRadioButton)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(jTextField1))
                                    .add(thirdPolinomRadioButton))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(secondPolinomRadioButton)
                                    .add(firstPolinomRadioButton)
                                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 340, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(countMatrixG, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 340, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(0, 0, Short.MAX_VALUE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 329, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
                            .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .add(38, 38, 38))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(firstPolinomRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(secondPolinomRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fourthPolinomRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(51, 51, 51)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(thirdPolinomRadioButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(customPolinomRadioButton)
                            .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
                    .add(jScrollPane2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(countMatrixG)
                    .add(jButton2))
                .add(43, 43, 43))
        );

        jTabbedPane1.addTab("Шаг 1", jPanel1);

        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField2KeyReleased(evt);
            }
        });

        jLabel4.setText("Введите G(x)");

        jLabel5.setText("Введите E(x)");

        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField3KeyReleased(evt);
            }
        });

        jLabel6.setText("F(x)=G(x)*x^r + R(x)");

        jLabel7.setText("H(x)=F(x) + E(x)");

        jTextField4.setEditable(false);

        jTextField5.setEditable(false);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel9.setText("Результат декодирования.");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 594, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()
                        .add(63, 63, 63)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .add(48, 48, 48)
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(jLabel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 118, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(jTextField5)
                                    .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(41, 41, 41)
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 327, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 327, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 327, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 347, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 327, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))))
                .addContainerGap(228, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .add(68, 68, 68)
                .add(jLabel9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jLabel10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(82, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Шаг 2", jPanel2);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 890, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        String s = polinomButtonGroup.getSelection().getActionCommand();
        System.out.println(s);
        int k = 0;
        jTextArea2.setText("");
        for (int[] i : Util.getMatrixH(Util.getMatrixG(Constants.polinom[Integer.parseInt(s) - 1]))) {
            for (int j : i) {
                if (k == 5) {
                    jTextArea2.append("| ");
                }
                jTextArea2.append(j + "  ");
                k++;
            }
            k = 0;
            jTextArea2.append("\n");
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void countMatrixGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_countMatrixGActionPerformed
        String s = polinomButtonGroup.getSelection().getActionCommand();
        System.out.println(s);
        int k = 0;
        jTextArea1.setText("");
        for (int[] i : Util.getMatrixG(Constants.polinom[Integer.parseInt(s) - 1])) {
            for (int j : i) {
                if (k == 5) {
                    jTextArea1.append("| ");
                }
                jTextArea1.append(j + "  ");
                k++;
            }
            k = 0;
            jTextArea1.append("\n");
        }
    }//GEN-LAST:event_countMatrixGActionPerformed

    private void jTextField1InputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTextField1InputMethodTextChanged
        // TODO add your handling code here:
        String s = jTextField1.getText();
        int k = 0;
        for (char i : s.toCharArray()) {
            if (i == '1') {
                g[k] = 1;
            } else if (i == '0') {
                g[k] = 0;
            } else {
                jTextField1.setText("Исходные данные не корректны!");
                break;
            }
        }
    }//GEN-LAST:event_jTextField1InputMethodTextChanged

    private void customPolinomRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customPolinomRadioButtonActionPerformed
    }//GEN-LAST:event_customPolinomRadioButtonActionPerformed

    private void calcTable() {
        String s = polinomButtonGroup.getSelection().getActionCommand();
        table = TableMethod.getTable(Util.getMatrixG(Constants.polinom[Integer.parseInt(s) - 1]));
        res = TableMethod.mulVecOnMatrix(Constants.polinom[Integer.parseInt(s) - 1], TableMethod.getTransporate(Util.getMatrixH(Util.getMatrixG(Constants.polinom[Integer.parseInt(s) - 1]))));
    }

    private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyReleased
        String s = "";
        if (jTextField2.getText().length() == 5) {
            if (jTextField2.getText().matches("(0|1)*")) {
                jTextField2.setBackground(Color.green);
                jLabel8.setText("Информация, введенная в поле G(x), корректна.");
                f = TableMethod.getF(jTextField2.getText(), table);
                for (int i : f) {
                    s += i;
                }
                System.out.println(s);
                jTextField4.setText(s);
            } else {
                jTextField2.setBackground(Color.red);
                jLabel8.setText("Информация, вводимая в поле G(x), должна состоять только из 0 и 1.");
            }
        } else {
            jLabel8.setText("Длина информаци, вводимая в поле G(x), должна быть равна 5 символам.");
            jTextField2.setBackground(Color.red);
        }
    }//GEN-LAST:event_jTextField2KeyReleased

    private void jTextField3KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyReleased
        String s = "", s1 = "", s2 = "";
        int[] ves;
        if (jTextField3.getText().length() == 15) {
            if (jTextField3.getText().matches("(0|1)*")) {
                jTextField3.setBackground(Color.green);
                jLabel8.setText("Информация, введенная в поле G(x), корректна.");
                h = TableMethod.getH(jTextField3.getText(), f);
                for (int i : h) {
                    s += i;
                }
                System.out.println(s);
                jTextField5.setText(s);
                System.out.println();
                int[][] res1;
                res1 = new int[table.length][table[0].length];
                ves = TableMethod.decode(h, table, res1);
                int[] row = new int[1];
                int minVes = TableMethod.getMinVes(ves, row);
                s = "";
                int a=row[0];
                for (int i = 0; i < res1[a].length; i++) {
                    s += h[i];
                    s1 += res1[a][i];
                    s2 += table[a][i];
                }
                if (minVes == 0) {
                    if (!TableMethod.cmpVec(f,table[a])) {
                        jLabel10.setText("Найдена необнаруживаемая ошибка.");
                        jLabel11.setText("");
                        jLabel12.setText("");
                        jLabel13.setText("");
                    }
                    else {
                        jLabel10.setText("Ошибок нет.");
                        jLabel11.setText("");
                        jLabel12.setText("");
                        jLabel13.setText("");
                    }
                } else {
                    jLabel10.setText("Обнаружена " + minVes + "-кратная ошибка.");
                    jLabel13.setText("В " + s1 + " битах.");
                    jLabel11.setText("До декодирования: " + s);
                    jLabel12.setText("После декодирования: " + s2);
                }
            } else {
                jTextField3.setBackground(Color.red);
                jLabel8.setText("Информация, вводимая в поле G(x), должна состоять только из 0 и 1.");
            }
        } else {
            jLabel8.setText("Длина информаци, вводимая в поле G(x), должна быть равна 15 символам.");
            jTextField3.setBackground(Color.red);
        }
    }//GEN-LAST:event_jTextField3KeyReleased

    private void thirdPolinomRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_thirdPolinomRadioButtonActionPerformed
        calcTable();
    }//GEN-LAST:event_thirdPolinomRadioButtonActionPerformed

    private void fourthPolinomRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fourthPolinomRadioButtonActionPerformed
        calcTable();
    }//GEN-LAST:event_fourthPolinomRadioButtonActionPerformed

    private void secondPolinomRadioButtonActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_secondPolinomRadioButtonActionPerformed1
        calcTable();
    }//GEN-LAST:event_secondPolinomRadioButtonActionPerformed1

    private void firstPolinomRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_firstPolinomRadioButtonActionPerformed
        calcTable();
    }//GEN-LAST:event_firstPolinomRadioButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton countMatrixG;
    private javax.swing.JRadioButton customPolinomRadioButton;
    private javax.swing.JRadioButton fourthPolinomRadioButton;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.ButtonGroup polinomButtonGroup;
    private javax.swing.JRadioButton secondPolinomRadioButton;
    private javax.swing.JRadioButton thirdPolinomRadioButton;
    // End of variables declaration//GEN-END:variables
}
